#!/bin/bash
#=================================================================
# date: 2022-01-04 21:20:01
# title: run_repnet
# author: QRS
#=================================================================

CUR_FIL=${BASH_SOURCE[0]}
TOP_DIR=`cd $(dirname $CUR_FIL)/..; pwd`

VENDOR=hzcsai_com
PROJECT=frepai_tf
REPOSITORY="$VENDOR/$PROJECT"

minio_server_url='frepai-1301930378.cos.ap-beijing.myqcloud.com'
minio_access_key='AKIDV7XjgOr42nMhneGdmiPs66rNioeFafeT'
minio_secret_key='d190cxQk0CHCtLXjhQt65tUr2yf7KI1V'

NAME=${PROJECT}-model

__start_frepai()
{
    docker run -dit --runtime nvidia --name ${NAME} \
        --shm-size=10g --ulimit memlock=-1 --ulimit stack=67108864 \
        --network host --restart unless-stopped \
        --env TOPIC=zmq.repnet_tf.inference \
        --env PYTHONPATH=/frepai/codes/app:/frepai/codes/projects/repnet-cli \
        --env TF_CPP_MIN_LOG_LEVEL=3 \
        --env MINIO_SERVER_URL=$minio_server_url \
        --env MINIO_ACCESS_KEY=$minio_access_key \
        --env MINIO_SECRET_KEY=$minio_secret_key \
        --volume /frepai/data:/frepai/data \
        --volume /frepai/data/ckpts/repnet_tf:/ckpts \
        --volume /frepai/data/users/outputs:/outputs \
        --volume $TOP_DIR/app:/frepai/codes/app \
        --volume $TOP_DIR/entrypoint.sh:/entrypoint.sh \
        --volume $TOP_DIR/projects/repnet-cli:/frepai/codes/projects/repnet-cli \
        $REPOSITORY -s repnet_tf
}

if [[ x$1 == x1 ]]
then
    docker container stop ${NAME} > /dev/null
    docker container rm ${NAME} > /dev/null
fi

__start_frepai
